package zdsoft.nbfsc.task;

import sense.vitality.ioc.SenseInjection;
import sense.vitality.protocol.ObjectResult;
import sense.vitality.protocol.Stuff;
import sense.vitality.security.Authentication;
import sense.vitality.security.Passport;
import sense.vitality.security.RestrictionAnalyst;
import sense.vitality.task.BaseTask;

/**
 *
 * @author elegance
 */
public class AuthenticateTask extends BaseTask {

    @SenseInjection
    private Authentication authentication;

    @Override
    protected Stuff execute(Stuff request) {
        String taskName = request.getStringItem("taskName");
        Passport passport = request.getTargetObject(Passport.class);
        ObjectResult<RestrictionAnalyst> orr = authentication.authenticate(passport, taskName);
        Stuff resp = request.instanceResponse(orr.getResult());
        if (resp.getResult().isSuccess()) {
            resp.setTargetObject(orr.getTargetObject());
        }
        return resp;
    }

}
